import Mock from 'mockjs'
import { Random } from 'mockjs'

const data = Mock.mock({
    // code: '200',
    // message: '请求成功',
    "data|2-5": [
        {
            "id|+1": 1,
            'name': '@cword(2,3)',
            "tel|10000000000-19999999999":1,
            'address':Random.county(true)
        }
    ]
})

Mock.mock('/address', 'post', (config) => {
    data.code = '200'
    data.message = '请求成功'
    // console.log(JSON.parse(config.body))
    data.data.forEach((item: any)=>{
        item.id = item.id+''
    })
    data.data[0].isDefault = true
    return data
})

Mock.mock('/addressstep', 'post', (config) => {
    // console.log(JSON.parse(config.body))
    const str = JSON.parse(config.body)
    data.data.push(str)
    data.code = '200'
    data.message = '添加成功'
    return data
})

Mock.mock('/modifyAdd', 'post', (config) => {
    // console.log(JSON.parse(config.body))
    const {id,name,tel,address} = JSON.parse(config.body)
    const res = data.data.find((item: any)=>{
        return String(item.id) === id
    })
    res.name = name
    res.tel = tel
    res.address = address

    data.code = '200'
    data.message = '修改成功'
    return data
})